/*
  c-pthread-queue - c implementation of a bounded buffer queue using posix threads
  Copyright (C) 2008  Matthew Dickinson

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <pthread.h>
#include <stdio.h>

#ifndef __QUEUE_H
#define __QUEUE_H

#define QUEUE_INITIALIZER(buffer) { buffer, sizeof(buffer) / sizeof(buffer[0]), 0, 0, 0, PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER }

typedef struct queue
{
  void **buffer;
  const int capacity;
  int size;
  int in;
  int out;
  pthread_mutex_t mutex;
  pthread_cond_t cond_full;
  pthread_cond_t cond_empty;
} queue_t;


typedef struct Queue {
  queue_t *tcpQ;

  queue_t *Q1;

  queue_t *logQ;
} Queue_t;

void queue_enqueue(queue_t *, void*);
void* queue_dequeue(queue_t *);
int queue_size(queue_t *);

#endif
